package com.fenghongzhang.day003;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RemoteViews;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void send(View view) {
        //构造者
        Notification.Builder builder = new Notification.Builder(this);

        //小图标***
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentTitle("标题");
        builder.setContentText("内容");
        builder.setWhen(System.currentTimeMillis());

        builder.setAutoCancel(true);

        //锁屏通知
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);

        //有了对象.
        Notification build = builder.build();

        //通知管理者对象.(NotificationManager)- > 发送通知,清除通知,更新通知.
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        //发送通知
        /**
         * int 随意, 不要0
         * 通知对象
         */
        manager.notify(1,build);

    }


    public void send2(View view) {

        //构造者
        Notification.Builder builder = new Notification.Builder(this);

        //小图标***
        builder.setSmallIcon(R.mipmap.ic_launcher);

        //自定义布局-> 执行在通知栏里面 -> 系统的服务
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notify_layout);


        remoteViews.setTextViewText(R.id.notify_tv,"哈哈哈哈哈");
        remoteViews.setImageViewResource(R.id.notify_img,R.mipmap.ic_launcher_round);

        //版本24
        builder.setCustomContentView(remoteViews);

        //有了对象.
        Notification build = builder.build();

        //通知管理者对象.(NotificationManager)- > 发送通知,清除通知,更新通知.
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        //发送通知
        /**
         * int 随意, 不要0
         * 通知对象
         */
        manager.notify(1,build);
    }

    public void send3(View view) {

        //构造者
        Notification.Builder builder = new Notification.Builder(this);

        //小图标***
        builder.setSmallIcon(R.mipmap.ic_launcher);

        //自定义布局-> 执行在通知栏里面 -> 系统的服务
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notify_layout);

        remoteViews.setTextViewText(R.id.notify_tv,"呵呵呵");
        remoteViews.setImageViewResource(R.id.notify_img,R.mipmap.ic_launcher);

        //版本24
        builder.setCustomContentView(remoteViews);

        //有了对象.
        Notification build = builder.build();

        //通知管理者对象.(NotificationManager)- > 发送通知,清除通知,更新通知.
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        //发送通知
        /**
         * int 随意, 不要0
         * 通知对象
         */
        //相同id代表更新.
        manager.notify(1,build);
    }

    public void send4(View view) {
//通知管理者对象.(NotificationManager)- > 发送通知,清除通知,更新通知.
        final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        //构造者
        final Notification.Builder builder = new Notification.Builder(this);
        //小图标***
        builder.setSmallIcon(R.mipmap.ic_launcher);

        /**
         * 1 最大值
         * 2 当前进度值
         * 3,是否模糊
         */
//        builder.setProgress(100,10,true);
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            int index = 0;
            @Override
            public void run() {
                builder.setProgress(100,index,false);
                index += 10;
                manager.notify(1,builder.build());
                if (index >= 100){
                    timer.cancel();
                    manager.cancel(1);
                }
            }
        },0,1000);


        //有了对象.
        manager.notify(1, builder.build());
    }

    public void send5(View view) {
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        Notification.Builder mBuilder0 = new Notification.Builder(this);
        Notification.Builder mBuilder1 = new Notification.Builder(this);
        Notification.Builder mBuilder2 = new Notification.Builder(this);
        Notification.Builder mBuilder3 = new Notification.Builder(this);

        //消息分组属性,group相同才能分到一组
        mBuilder0.setGroup("2");
        mBuilder0.setSmallIcon(R.mipmap.ic_launcher);
//        //被设置setGroupSummary为true的消息会隐藏内容,其内容会显示另外分组成员信息.
//        mBuilder0.setGroupSummary(true);
        mBuilder0.setContentText("11111111");
        mBuilder0.setContentTitle("222222222");

        mBuilder1.setGroup("2");
        mBuilder1.setSmallIcon(R.mipmap.ic_launcher);
        mBuilder1.setGroupSummary(true);
        mBuilder1.setContentText("333333");
        mBuilder1.setContentTitle("44444444");


        mBuilder2.setGroup("2");
        mBuilder2.setSmallIcon(R.mipmap.ic_launcher);
//        mBuilder2.setGroupSummary(true);
        mBuilder2.setContentText("55555555555555555");
        mBuilder2.setContentTitle("66666666666");

        mBuilder3.setGroup("2");
        mBuilder3.setSmallIcon(R.mipmap.ic_launcher);
//        mBuilder3.setGroupSummary(true);
        mBuilder3.setContentText("77777");
        mBuilder3.setContentTitle("8888888");


        manager.notify(0,mBuilder0.build());
        manager.notify(1,mBuilder1.build());
        manager.notify(2,mBuilder2.build());
        manager.notify(3,mBuilder3.build());
    }

    public void send6(View view) {
        //构造者
        Notification.Builder builder = new Notification.Builder(this);

        //小图标***
        builder.setSmallIcon(R.mipmap.ic_launcher);


        //通知的样式
//        Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle();
        //位图.BitmapFactory
        /**
         * 可以从指定路径,或者资源,加载一个图片.
         */
//        BitmapFactory.decodeStream(is)
//        Bitmap bitmap = BitmapFactory.decodeFile();
//        ImageView imageView = new ImageView();
//        imageView.setImageResource(R.mipmap.ic_launcher);
//        imageView.setImageBitmap(bitmap);

//        bigPictureStyle.bigPicture(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher));
//        builder.setStyle(bigPictureStyle);


        //列表魔兽
        Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
        inboxStyle.addLine("haha");
        inboxStyle.addLine("没毛病");
        inboxStyle.addLine("没毛病");
        inboxStyle.addLine("没毛病");
        builder.setStyle(inboxStyle);


        //有了对象.
        Notification build = builder.build();

        //通知管理者对象.(NotificationManager)- > 发送通知,清除通知,更新通知.
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        //发送通知
        /**
         * int 随意, 不要0
         * 通知对象
         */
        manager.notify(1,build);
    }

    public void send7(View view) {
        //构造者
        Notification.Builder builder = new Notification.Builder(this);
        //小图标***
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentTitle("表题");

        builder.setAutoCancel(true);

        Intent intent = new Intent(this, Main2Activity.class);
        PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);


        //可以弹出
        builder.setPriority(Notification.PRIORITY_MAX);
        //设置,声音,震动,灯光.
        builder.setDefaults(Notification.DEFAULT_ALL);


        //可交互
        builder.setContentIntent(activity);

        //有了对象.
        Notification build = builder.build();
        //通知管理者对象.(NotificationManager)- > 发送通知,清除通知,更新通知.
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(1,build);
    }
}
